<html>
<head>
    <meta charset="UTF-8">
    <title>医生修改</title>
</head>
<link rel="stylesheet" href="/static/layui/css/layui.css"/>
<body>
<form class="layui-form" action="" lay-filter="edit">
    <input type="hidden" name="did">
    <div class="layui-form-item">
        <label class="layui-form-label">所属医院</label>
        <div class="layui-input-inline layui-col-md4">
            <select name="hid" id="hid" lay-filter="aihao">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline layui-col-md4">
                <input type="tel" name="dphone" id = "dphone" lay-verify="required|phone" placeholder="请输入手机号正确格式11位" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">确认账号</label>
            <div class="layui-input-inline layui-col-md4">
                <input type="tel"  lay-verify="required|phone|confirmPass" placeholder="请输入手机号正确格式11位" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="dpassword" placeholder="请输入密码6-12位" lay-verify= "pass" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请务必填写账号</div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline layui-col-md4">
                <input type="text" name="demail" lay-verify="email" placeholder="请输入正确邮箱格式" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否发送信息：</label>
        <div class="layui-input-block">
            <input type="radio" name="dsex" value="0" title="是">
            <input type="radio" name="dsex" value="1" title="否" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
</body>
<script src="/static/js/system.js"></script>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    //医院下拉款
    layui.use(['form','laydate'], function() {
        var form = layui.form;
        $.ajax({
            url: "/hospital/findAll",
            type: "post",
            // data:{},
            dataType: "json",
            success: function (res) {
                console.log(res)
                $.each(res.date.list, function (i, obj) {
                    console.log(obj);
                    $("#hid").append('<option value="' + obj.hid + '">' + obj.hname + '</option>');
                });
                form.render('select'); //刷新select选择框渲染
            }
        });
    });
    //Demo
    layui.use(['form', 'layer'], function () {
        var layer = layui.layer
            ,form = layui.form
            ,$= layui.$;
        $.ajax({
            url: '/doctor/findId',
            type: "post",
            dataType: "json",
            data: {"did": getQueryString("did")},
            success: function (da) {
                console.log(da)
                if (da.code == 200) {
                    form.val("edit", da.date);
                    form.val("edit", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                        "dtime": layui.util.toDateString(da.dtime, 'yyyy-MM-dd')
                    });
                } else {
                    parent.layer.msg("详情查询失败！");
                }
            }
        });
        //校验账号
        form.verify({
            confirmPass : function(value) {
                if ($('input[name=dphone]').val() !== value)
                    return '两次账号输入不一致！';
            }
        });
        //监听提交 15039939677
        form.on('submit(formDemo)', function (data) {
            var data1 = form.val("edit");
            $.ajax({
                url: '/doctor/update',
                type: "post",
                dataType: "json",
                data: data1,
                success: function (da) {
                    console.log(da)
                    if (da.code == 200) {
                        layer.alert("修改成功！", function () {
                            // window.parent.location.reload();//刷新父页面
                            // parent.layer.close(layer.index);//关闭弹出层
                            parent.layer.closeAll();
                        });
                    } else {
                        layer.msg("修改失败！");
                    }
                }
            });
            return false;
        });
    });
</script>
</html>
